package com.osmino.core.style;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

public class StyleAttribute {

	public static final int NONE = 0;

	public static final int VIEW_IMAGE_BUTTON = 1;
	public static final int VIEW_IMAGE_VIEW = 2;
	public static final int VIEW_TEXT_VIEW = 3;

	public static final int ATT_IMAGE_BUTTON_BACKGROUND = 101;
	public static final int ATT_IMAGE_BUTTON_FOREGROUND = 102;

	public static final int ATT_IMAGE_VIEW_BACKGROUND = 103;
	public static final int ATT_IMAGE_VIEW_FOREGROUND = 104;

	public static final int ATT_TEXT_VIEW_BACKGROUND = 105;
	public static final int ATT_TEXT_VIEW_TEXT_COLOR = 106;
	public static final int ATT_TEXT_VIEW_TEXT_SIZE = 107;

	private int mViewId = NONE;
	private int mTypeOfView = NONE;
	private int mAttribute = NONE;
	private int mValue = NONE;
	
	private static HashMap<Integer, HashSet<Integer>> map;
	
	static{
		map = getViewMap();
	}
	
	public static HashMap<Integer, HashSet<Integer>> getViewMap() {
		if(map!=null){
			return map;
		}
		HashMap<Integer, HashSet<Integer>> map = new HashMap<Integer, HashSet<Integer>>();
		map.put(VIEW_IMAGE_BUTTON, new HashSet<Integer>(Arrays.asList(ATT_IMAGE_BUTTON_BACKGROUND, ATT_IMAGE_BUTTON_FOREGROUND)));
		map.put(VIEW_IMAGE_VIEW, new HashSet<Integer>(Arrays.asList(ATT_IMAGE_VIEW_BACKGROUND, ATT_IMAGE_VIEW_FOREGROUND)));
		map.put(VIEW_TEXT_VIEW, new HashSet<Integer>(Arrays.asList(ATT_TEXT_VIEW_BACKGROUND, ATT_TEXT_VIEW_TEXT_COLOR, ATT_TEXT_VIEW_TEXT_SIZE)));
		return map;
	}

	public StyleAttribute() {
	}

	public StyleAttribute(int viewId, int typeOfView, int attribute, int value) {
		mViewId = viewId;
		mTypeOfView = typeOfView;
		mAttribute = attribute;
		mValue = value;
	}

	public void setAttribute(int viewId, int typeOfView, int attribute,
			int value) {
		mViewId = viewId;
		mTypeOfView = typeOfView;
		mAttribute = attribute;
		mValue = value;
	}

	/**
	 * return true if everything in attribute is equal except value
	 */

	@Override
	public boolean equals(Object o) {
		if (!o.getClass().isInstance(this)) {
			return false;
		}
		StyleAttribute sa = (StyleAttribute) o;
		if (mViewId == sa.getViewId() && mTypeOfView == sa.getTypeOfView()
				&& mAttribute == sa.getAttribute()) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		throw new UnsupportedOperationException();
	}

	public int getViewId() {
		return mViewId;
	}

	public void setViewId(int mViewId) {
		this.mViewId = mViewId;
	}

	public int getTypeOfView() {
		return mTypeOfView;
	}

	public void setTypeOfView(int mTypeOfView) {
		this.mTypeOfView = mTypeOfView;
	}

	public int getAttribute() {
		return mAttribute;
	}

	public void setAttribute(int mAttribute) {
		this.mAttribute = mAttribute;
	}

	public int getValue() {
		return mValue;
	}

	public void setValue(int mValue) {
		this.mValue = mValue;
	}

	public boolean isValid() {
		boolean result;
		if (mAttribute == NONE || mTypeOfView == NONE || mValue == NONE || mViewId == NONE) {
			result = false;
		} 
		else {
			if(getViewMap().containsKey(mTypeOfView)){
				if(getViewMap().get(mTypeOfView).contains(mAttribute)){
					result =  true;
				}
				else{
					result = false;
				}
			}
			else{
				result = false;
			}
		}
		return result;
	}
}